home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / asteroid.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  3KB  |  173 lines

  1. /***************************************************************************
  2.  
  3.   machine.c
  4.  
  5.   Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  6.   I/O ports)
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11. #include "machine/atari_vg.h"
  12. #include "vidhrdw/avgdvg.h"
  13.  
  14. int asteroid_interrupt (void)
  15. {
  16.     /* Turn off interrupts if self-test is enabled */
  17.     if (readinputport(0) & 0x80)
  18.         return ignore_interrupt();
  19.     else
  20.         return nmi_interrupt();
  21. }
  22.  
  23. int llander_interrupt (void)
  24. {
  25.     /* Turn off interrupts if self-test is enabled */
  26.     if (readinputport(0) & 0x02)
  27.         return nmi_interrupt();
  28.     else
  29.         return ignore_interrupt();
  30. }
  31.  
  32. READ_HANDLER( asteroid_IN0_r )
  33. {
  34.  
  35.     int res;
  36.     int bitmask;
  37.  
  38.     res=readinputport(0);
  39.  
  40.     bitmask = (1 << offset);
  41.  
  42.     if (cpu_gettotalcycles() & 0x100)
  43.         res |= 0x02;
  44.     if (!avgdvg_done())
  45.         res |= 0x04;
  46.  
  47.     if (res & bitmask)
  48.         res = 0x80;
  49.     else
  50.         res = ~0x80;
  51.  
  52.     return res;
  53. }
  54.  
  55. READ_HANDLER( asteroib_IN0_r )
  56. {
  57.     int res;
  58.  
  59.     res=readinputport(0);
  60.  
  61. //    if (cpu_gettotalcycles() & 0x100)
  62. //        res |= 0x02;
  63.     if (!avgdvg_done())
  64.         res |= 0x80;
  65.  
  66.     return res;
  67. }
  68.  
  69. /*
  70.  * These 7 memory locations are used to read the player's controls.
  71.  * Typically, only the high bit is used. This is handled by one input port.
  72.  */
  73.  
  74. READ_HANDLER( asteroid_IN1_r )
  75. {
  76.     int res;
  77.     int bitmask;
  78.  
  79.     res=readinputport(1);
  80.     bitmask = (1 << offset);
  81.  
  82.     if (res & bitmask)
  83.         res = 0x80;
  84.     else
  85.          res = ~0x80;
  86.     return (res);
  87. }
  88.  
  89. READ_HANDLER( asteroid_DSW1_r )
  90. {
  91.     int res;
  92.     int res1;
  93.  
  94.     res1 = readinputport(2);
  95.  
  96.     res = 0xfc | ((res1 >> (2 * (3 - (offset & 0x3)))) & 0x3);
  97.     return res;
  98. }
  99.  
  100.  
  101. WRITE_HANDLER( asteroid_bank_switch_w )
  102. {
  103.     static int asteroid_bank = 0;
  104.     int asteroid_newbank;
  105.     unsigned char *RAM = memory_region(REGION_CPU1);
  106.  
  107.  
  108.     asteroid_newbank = (data >> 2) & 1;
  109.     if (asteroid_bank != asteroid_newbank) {
  110.         /* Perform bankswitching on page 2 and page 3 */
  111.         int temp;
  112.         int i;
  113.  
  114.         asteroid_bank = asteroid_newbank;
  115.         for (i = 0; i < 0x100; i++) {
  116.             temp = RAM[0x200 + i];
  117.             RAM[0x200 + i] = RAM[0x300 + i];
  118.             RAM[0x300 + i] = temp;
  119.         }
  120.     }
  121.     osd_led_w (0, ~(data >> 1));
  122.     osd_led_w (1, ~data);
  123. }
  124.  
  125. WRITE_HANDLER( astdelux_bank_switch_w )
  126. {
  127.     static int astdelux_bank = 0;
  128.     int astdelux_newbank;
  129.     unsigned char *RAM = memory_region(REGION_CPU1);
  130.  
  131.  
  132.     astdelux_newbank = (data >> 7) & 1;
  133.     if (astdelux_bank != astdelux_newbank) {
  134.         /* Perform bankswitching on page 2 and page 3 */
  135.         int temp;
  136.         int i;
  137.  
  138.         astdelux_bank = astdelux_newbank;
  139.         for (i = 0; i < 0x100; i++) {
  140.             temp = RAM[0x200 + i];
  141.             RAM[0x200 + i] = RAM[0x300 + i];
  142.             RAM[0x300 + i] = temp;
  143.         }
  144.     }
  145. }
  146.  
  147. WRITE_HANDLER( astdelux_led_w )
  148. {
  149.     osd_led_w (offset, ~data);
  150. }
  151.  
  152. void asteroid_init_machine(void)
  153. {
  154.     asteroid_bank_switch_w (0,0);
  155. }
  156.  
  157. /*
  158.  * This is Lunar Lander's Inputport 0.
  159.  */
  160. READ_HANDLER( llander_IN0_r )
  161. {
  162.     int res;
  163.  
  164.     res = readinputport(0);
  165.  
  166.     if (avgdvg_done())
  167.         res |= 0x01;
  168.     if (cpu_gettotalcycles() & 0x100)
  169.         res |= 0x40;
  170.  
  171.     return res;
  172. }
  173.